package com.bluejie.bluej.java.design.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by bluej on 2018-03-06.
 */
public class MyProxy2 {
      public static  <T> T getInstance(Object target){

        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("--MyProxy2--invoke()--");
                return method.invoke(target,args);
            }
        });

    }
}
